package com.yangchoi.jetpackcompose.ui.main.viewmodel

import com.yangchoi.lib_base.base.BaseViewModel
import com.yangchoi.lib_base.network.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor(private val apiService: ApiService) : BaseViewModel(){

    fun dispatch(event: LoginEvent,username:String,password:String,loginCallback:()->Unit){
        when(event){
            LoginEvent.OnLogin -> {
                launchFlow(
                    requestBlock = { apiService.login(username, password)},
                    response = {
                        loginCallback.invoke()
                    }
                )
            }
        }
    }

}

sealed class LoginEvent{
    object OnLogin : LoginEvent()
}